//
//  CommentCell.m
//  lvtu
//
//  Created by Apple on 12-4-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CommentCell.h"

@implementation CommentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        tripImageView = [[EGOImageView alloc] initWithFrame:
                         CGRectMake(10, 10, 50, 50)];
        //tripImageView.image = [UIImage imageNamed:@"bg_trip_default.png"];
        [tripImageView setPlaceholderImage:[UIImage imageNamed:@"bg_trip_default.png"]];
        [self addSubview:tripImageView];
        
        creattimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 15, 50, 16)];
        creattimeLabel.text = @"2012-03-12";
        creattimeLabel.backgroundColor = [UIColor clearColor]; 
        //creattimeLabel.textColor = [UIColor blackColor];
        creattimeLabel.font = [UIFont systemFontOfSize:9.0f];
        creattimeLabel.numberOfLines = 0;
        creattimeLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:creattimeLabel];
        
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, 100, 20)];
        nameLabel.text = @"浪漫之旅";
        nameLabel.backgroundColor = [UIColor clearColor]; 
        nameLabel.font = [UIFont systemFontOfSize:12.0f];
        nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:nameLabel];
        
        commentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(70, 40, 15, 16)];
        commentImageView.image = [UIImage imageNamed:@"icn_comment.png"];
        [self addSubview:commentImageView];
        
        commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(88, 35, 100, 20)];
        commentLabel.text = @"评论(0)";
        commentLabel.backgroundColor = [UIColor clearColor]; 
        commentLabel.font = [UIFont systemFontOfSize:10.0f];
        commentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:commentLabel];
        
        newcommentLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 35, 50, 20)];
        newcommentLabel.text = @"新评论(0)";
        newcommentLabel.backgroundColor = [UIColor clearColor]; 
        newcommentLabel.font = [UIFont systemFontOfSize:10.0f];
        newcommentLabel.textColor = [UIColor redColor];
        newcommentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
//        [self addSubview:newcommentLabel];
    }
    return self;
}

- (void)updateComment:(MessageInfo*)info
{
    if (info.coverurl && ![info.coverurl isEqualToString:@""]) {
        [tripImageView setImageURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.wxlvtu.com/img.php?filename=%@",info.coverurl]]];
    }
    else {
        [tripImageView setImage:[UIImage imageNamed:@"bg_trip_default.png"]];
    }
    if ([info.creattime isEqualToString:@"0"]) {
        creattimeLabel.text = @"";
    }
    else
    {
        creattimeLabel.text = info.creattime;
    }
    nameLabel.text = info.name;
    commentLabel.text = [NSString stringWithFormat:@"评论(%@)",info.commentcount];
    if ([info.newcommentcount intValue] > 0 ) {
        [self addSubview:newcommentLabel];
        newcommentLabel.text  = [NSString stringWithFormat:@"新评论(%@)",info.newcommentcount];
    }
    else {
        [newcommentLabel removeFromSuperview];
    }
}

- (void)updateCommentCount:(MessageInfo*)info
{
    commentLabel.text = [NSString stringWithFormat:@"评论(%d)",[info.commentcount intValue]+1];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    //[super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
